var t = require("../../../@babel/runtime/helpers/defineProperty"), i = getApp();

Page({
    data: {
        tabsIndex: 1,
        circleId: 0,
        circleInfo: {},
        page: 1,
        isLoadMore: !0,
        total_page: 0,
        listData: [],
        networkLoading: !1,
        topData: [],
        adminOperationshow: !1,
        adminOperationInfo: []
    },
    onLoad: function(t) {
        console.log("第一次执行"), this.data.circleId = t.circleId, this.getDetails(), this.getListData(), 
        this.getTopData();
    },
    updateView: function() {
        this.getDetails(), this.getListData();
    },
    gotoCircleMyRelease: function(t) {
        console.log(t);
        var i = t.currentTarget.dataset.item;
        wx.navigateTo({
            url: "/packageH/circleCommunity/circleMyRelease/circleMyRelease?member_id=" + i.member_id + "&circleId=" + this.data.circleId
        });
    },
    getTopData: function() {
        var t = this, e = {
            circle_id: this.data.circleId,
            is_top: 1
        }, a = i.getNetAddresss("plugin.circle.frontend.circle-invitation.get-circle-invitation-list");
        i._postNetWork({
            url: a,
            data: e,
            success: function(e) {
                var a = e.data;
                if (1 != a.result) return i.tips(a.msg);
                t.setData({
                    topData: a.data.data
                });
            }
        });
    },
    setTabsIndex: function(t) {
        var i = t.currentTarget.dataset.index;
        this.setData({
            tabsIndex: i,
            networkLoading: !1
        }), this.getListData();
    },
    initData: function() {
        this.setData({
            page: 1,
            total_page: 0,
            isLoadMore: !0,
            networkLoading: !1
        });
    },
    adminOperationshowClose: function() {
        this.setData({
            adminOperationshow: !1
        });
    },
    onSelect: function(t) {
        var i = t.detail;
        "del" == i.type ? this.delCircle(i.id, i.index) : this.setCircleReview(i.type, i.id, i.index), 
        this.adminOperationshowClose();
    },
    adminBtn: function(t) {
        var i = t.currentTarget.dataset.item;
        "del" == i.type ? this.delCircle(i.id, i.index) : this.setCircleReview(i.type, i.id, i.index), 
        this.adminOperationshowClose();
    },
    managementBtn: function(t) {
        var i = t.currentTarget.dataset.item, e = t.currentTarget.dataset.index, a = [];
        1 == this.data.circleInfo.is_master && (a = [ {
            type: "is_top",
            id: i.id,
            index: e,
            img: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/micro_communities/detail_roof@2x.png",
            name: 1 == i.is_top ? "取消置顶" : "置顶"
        }, {
            type: "is_recommend",
            id: i.id,
            index: e,
            img: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/micro_communities/detail_recommend@2x.png",
            name: 1 == i.is_recommend ? "取消推荐" : "推荐"
        }, {
            type: "is_show",
            id: i.id,
            index: e,
            img: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/micro_communities/detail_invisible@2x.png",
            name: 1 == i.is_show ? "取消未加入可见" : "未加入可见"
        } ]), a.push({
            type: "del",
            id: i.id,
            index: e,
            img: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/micro_communities/detail_delect@2x.png",
            name: "删除"
        }), this.setData({
            adminOperationInfo: a,
            adminOperationshow: !0
        });
    },
    setCircleReview: function(e, a, c) {
        var n = this, r = i.getNetAddresss("plugin.circle.frontend.circle-invitation.set-invitation-review");
        i._getNetWork({
            url: r,
            data: {
                circle_id: this.data.circleId,
                invitation_id: a,
                invitation_type: e
            },
            success: function(a) {
                var r = a.data;
                if (i.tips(r.msg), 1 == r.result) {
                    var s = 0;
                    0 == n.data.listData[c][e] && (s = 1);
                    var o = "listData[" + c + "]." + e;
                    n.setData(t({}, o, s));
                }
            }
        });
    },
    delCircle: function(t, e) {
        var a = this, c = i.getNetAddresss("plugin.circle.frontend.circle-invitation.del");
        i._getNetWork({
            url: c,
            data: {
                circle_id: this.data.circleId,
                invitation_id: t
            },
            success: function(t) {
                var c = t.data;
                if (i.tips(c.msg), 1 == c.result) {
                    var n = a.data.listData;
                    n.splice(e, 1), a.setData({
                        listData: n
                    });
                }
            }
        });
    },
    followMember: function(e) {
        var a, c, n = this, r = e.currentTarget.dataset.index, s = e.currentTarget.dataset.id, o = this.data.listData[r].is_attention, d = {
            attention_member_id: s
        };
        0 == o ? (a = 1, c = i.getNetAddresss("plugin.circle.frontend.circle-member.attention-member")) : 1 == o && (a = 0, 
        c = i.getNetAddresss("plugin.circle.frontend.circle-member.cancel-attention")), 
        i._getNetWork({
            url: c,
            data: d,
            success: function(e) {
                var c = e.data;
                i.tips(c.msg), 1 == c.result && n.data.listData.forEach(function(i, e) {
                    if (i.member_id == s) {
                        var c = "listData[" + e + "].is_attention";
                        n.setData(t({}, c, a));
                    }
                });
            }
        });
    },
    cancel: function() {
        this.setData({
            adminOperationshow: !1
        });
    },
    getDetails: function() {
        var t = this, e = i.getNetAddresss("plugin.circle.frontend.circle.get-circle");
        i._postNetWork({
            url: e,
            data: {
                circle_id: this.data.circleId
            },
            success: function(e) {
                var a = e.data;
                if (1 != a.result) return i.tips(a.msg);
                t.setData({
                    circleInfo: a.data
                }), wx.setNavigationBarTitle({
                    title: a.data.name
                }), console.log(a);
            }
        });
    },
    getListData: function() {
        var t = this;
        this.initData();
        var e = this.data, a = e.tabsIndex, c = {
            circle_id: e.circleId
        };
        0 == a ? c.is_attention = 1 : c.invitation_status = a;
        var n = i.getNetAddresss("plugin.circle.frontend.circle-invitation.get-circle-invitation-list");
        i._postNetWork({
            url: n,
            data: c,
            success: function(e) {
                var a = e.data;
                if (1 != a.result) return i.tips(a.msg);
                t.data.total_page = a.data.last_page, t.data.total_page || (t.data.total_page = 0), 
                t.setData({
                    listData: a.data.data,
                    networkLoading: !0
                }), console.log(a);
            }
        });
    },
    _getMoreData: function() {
        var t = this;
        if (this.data.isLoadMore = !1, !(this.data.page >= this.data.total_page)) {
            this.data.page += 1;
            var e = i.getNetAddresss("plugin.circle.frontend.circle-invitation.get-circle-invitation-list"), a = this.data, c = a.tabsIndex, n = {
                circle_id: a.circleId,
                page: a.page
            };
            0 == c ? n.is_attention = 1 : n.invitation_status = c, i._postNetWork({
                url: e,
                data: n,
                success: function(i) {
                    var e = i.data;
                    if (t.data.isLoadMore = !0, 1 === e.result) {
                        var a = t.data.listData.concat(e.data.data);
                        t.setData({
                            listData: a
                        });
                    } else t.data.page = t.data.page - 1, t.data.isLoadMore = !1;
                }
            });
        }
    },
    onReady: function() {},
    addCircle: function() {
        var t = this, e = this.data, a = e.circleInfo, c = e.circleId;
        if (1 != a.is_toll) {
            var n = i.getNetAddresss("plugin.circle.frontend.circle.add-circle");
            i._postNetWork({
                url: n,
                data: {
                    circle_id: c
                },
                success: function(e) {
                    var a = e.data;
                    i.tips(a.msg), 1 == a.result && t.getDetails();
                }
            });
        } else this.payAddCircle();
    },
    payAddCircle: function() {
        var t = this, e = this.data.circleId, a = i.getNetAddresss("plugin.circle.frontend.circle-pay.add-circle-order");
        i._postNetWork({
            url: a,
            data: {
                circle_id: e
            },
            success: function(e) {
                var a = e.data;
                if (1 != a.result) return i.tips(a.msg);
                t.createOrder(a.data.goods_id), console.log(a);
            }
        });
    },
    createOrder: function(t) {
        var e = this.data.circleId, a = [ {
            goods_id: t,
            total: 1,
            option_id: 0
        } ], c = i.getNetAddresss("plugin.circle.api.create.index");
        i._postNetWork({
            url: c,
            data: {
                circle_id: e,
                goods: a
            },
            success: function(t) {
                var e = t.data;
                i.tips(e.msg), 1 == e.result && (console.log(e), wx.navigateTo({
                    url: "/packageD/buy/orderPay/orderPay?order_id=" + e.data.order_ids + "&status=2"
                }));
            }
        });
    },
    gotoCircleSetting: function() {
        wx.navigateTo({
            url: "/packageH/circleCommunity/circleSetting/circleSetting?circleId=" + this.data.circleId
        });
    },
    gotoCircleIntroduce: function() {
        wx.navigateTo({
            url: "/packageH/circleCommunity/circleIntroduce/circleIntroduce?circleId=" + this.data.circleId
        });
    },
    gotoCircleSelect: function() {
        wx.navigateTo({
            url: "/packageH/circleCommunity/circleSelect/circleSelect?circleId=" + this.data.circleId
        });
    },
    gotoTopicDetails: function(t) {
        var i = t.currentTarget.dataset.item;
        if (1 == i.status) wx.navigateTo({
            url: "/packageH/circleCommunity/topicDetails/topicDetails?stickId=" + i.id
        }); else if (2 == i.status) {
            var e = this.data.listData.findIndex(function(t, e, a) {
                return t.id === i.id;
            });
            e = Math.ceil((e + 1) / 15), wx.navigateTo({
                url: "/packageH/circleCommunity/videoDetails/videoDetails?vid=" + i.id + "&page=" + e + "&circleId=" + this.data.circleId
            });
        }
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this._getMoreData() : console.log("没有更多数据");
    },
    onShareAppMessage: function() {
        return {
            path: "/packageH/circleCommunity/circleDetails/circleDetails?circleId=" + this.data.circleId
        };
    },
    onShareTimeline: function() {
        return {
            query: "circleId=".concat(this.data.circleId)
        };
    }
});